<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<jsp:include   page="common/header.jsp" flush="true">
    <jsp:param name="title" value="新增评估" /> 
</jsp:include>
    <jsp:include   page="common/left.jsp" flush="true"/>

	<!-- 右侧 -->
	<div class="record-add-page">
            <div class="container-fluid">
		<div class="row">
                    <div class="col-lg-12">
			<div class="panel">
                            <div class="panel-heading">
				<div class="row">
                                    <div class="left fl"><span class="text">+ 新增评估</span></div>
                                    <div class="right fr"><a href="javascript:;" class="record-add-heading-return"></a></div>
				</div>
                            </div>
                            <form id="addWxUserdetailForm">
				<div class="panel-body panel-body-one">
                                    <div class="panel-body-title"><div class="record-title-img"></div></div>
                                    <!-- 案件信息 -->
                                    <div class="panel-body-caseInfo">
					<h3>案件信息</h3>
					<div class="caseInfo-wrapper">
                                            <div class="caseInfo-name">
						<i>*</i> <span>罪&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</span>
                                                <select name="wxUserdetail.chargetype" id="">
                                                    <c:forEach items="${chargetypes}" var="chargetype" varStatus="st">
							<c:if test="${st.index gt 0 }">
                                                            <option value="${st.index}">${chargetype}</option>
							</c:if>
                                                    </c:forEach>
						</select>
                                            </div>
                                            <div class="caseInfo-title">
						<span>案件名称：</span> 
                                                <input type="text" name="wxUserdetail.chargename" />
                                            </div>
                                            <div class="caseInfo-common">
						<span>是否共同犯罪</span>
                                                <select name="wxUserdetail.isjointcrime" id="">
                                                    <c:forEach items="${isjointcrimes}" var="isjointcrime" varStatus="st">
							<c:if test="${st.index gt 0 }">
                                                            <option value="${st.index}">${isjointcrime}</option>
							</c:if>
                                                    </c:forEach>
						</select>
                                            </div>
                                            <div class="caseInfo-before">
						<span>是否初犯、偶犯、累犯</span> 
                                                <select name="wxUserdetail.crimetype" id="">
                                                    <c:forEach items="${crimetypes}" var="crimetype" varStatus="st">
							<c:if test="${st.index gt 0 }">
                                                            <option value="${st.index}">${crimetype}</option>
							</c:if>
                                                    </c:forEach>
						</select>
                                            </div>
                                            <div class="caseInfo-fact">
						<span>犯罪事实：</span>
						<textarea name="wxUserdetail.crimefact"></textarea>
                                            </div>
                                            <div class="caseInfo-result">
						<span>犯罪结果：</span>
						<textarea name="wxUserdetail.crimeresult"></textarea>
                                            </div>
					</div>
                                    </div>
                                    <!-- 个人信息 -->
                                    <div class="panel-body-personInfo">
                                        <h3>个人信息<button class="chaxun" type="button"></button></h3>
                                        <input type="hidden" name="wxUserlist.id" id="user_id" value="0" />
					<div class="personInfo-wrapper">
                                            <div class="personInfo-name">
						<i>*</i> <span>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</span> 
                                                <input type="text" name="wxUserlist.truename" id="user_truename" />
                                            </div>
                                            <div class="personInfo-card">
						<span>证件类型：</span> 
                                                <select name="wxUserlist.credtype" id="user_credtype">
                                                    <c:forEach items="${credtypes}" var="credtype" varStatus="st">
							<c:if test="${st.index gt 0 }">
                                                            <option value="${st.index}">${credtype}</option>
							</c:if>
                                                    </c:forEach>
						</select>
                                            </div>
                                            <div class="personInfo-num">
						<span>证件号码：</span> 
                                                <input type="text" name="wxUserlist.idcardno" id="user_idcardno" />
                                            </div>
                                            <div class="personInfo-sex">
						<span>性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</span>
                                                <select name="wxUserlist.sex" id="user_sex">
                                                    <option value="1">男</option>
                                                    <option value="2">女</option>
						</select>
                                            </div>
                                            <div class="personInfo-nation">
						<span>民&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;族：</span>
                                                <select name="wxUserlist.nation" id="user_nation">
                                                    <c:forEach items="${nations}" var="nation" varStatus="st">
							<c:if test="${st.index gt 0 }">
                                                            <option value="${st.index}">${nation}</option>
							</c:if>
                                                    </c:forEach>
						</select>
                                            </div>
                                            <div class="personInfo-age">
						<span>年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄：</span> 
                                                <input type="text" name="wxUserlist.age" id="user_age" />
                                            </div>
                                            <div class="parsonInfo-date">
						<span>出生日期：</span> 
                                                <input type="text" name="wxUserlist.birthday" class="layui-input" id="user_birthday" placeholder="2018-05-09" lay-key="1"/>
                                            </div>
                                            <div class="parsonInfo-city">
						<span>籍&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;贯：</span>
						<div class="friend-select" data-toggle="distpicker">
                                                    <div class="form-group">
							<select class="form-control" name="wxUserlist.province" id="user_province"></select>
                                                    </div>
                                                    <div class="form-group">
							<select class="form-control" name="wxUserlist.city" id="user_city"></select>
                                                    </div>
                                                    <div class="form-group">
							<select class="form-control" name="wxUserlist.district" id="user_district"></select>
                                                    </div>
						</div>
                                                <input type="text" id="user_address" name="wxUserlist.address" />
                                            </div>
					</div>
                                    </div>
                                    <!--个人信息end-->
                                    <!-- 家庭情况 -->
                                    <div class="panel-body-familyInfo">
					<h3>家庭情况</h3>
					<div class="familyInfo-wrapper">
                                            <div class="familyInfo-address">
						<span>家庭住址：</span> 
                                                <input type="text" name="wxUserdetail.familyaddress" />
                                            </div>
                                            <div class="familyInfo-married">
						<span>婚姻状况：</span>
						<input type="radio" name="wxUserdetail.marriagetype" value="" />
						<c:forEach items="${marriagetypes }" var="marriagetype" varStatus="st">
                                                    <c:if test="${st.index gt 0 }">
							<div class="married-item1">
                                                            <label for="" data-id="${st.index}"> <b>${marriagetype}</b></label>
							</div>
                                                    </c:if>
						</c:forEach>
                                            </div>
                                            <div class="familyInfo-age">
						<span>婚龄：</span> 
                                                <input type="text" name="wxUserdetail.marriageage" />
                                            </div>
                                            <div class="familyInfo-add">
						<div class="familyInfo-add-title">
                                                    <span>家庭成员情况：</span> <i class="icon"></i>
                                                    <input type="hidden" name="hasfamilytypes" id="hasfamilytypes" value="n" />
                                                    <div class="row">
							<div class="col-lg-6">
                                                            <div class="table-responsive">
                                                                    <table class="table table-bordered table-hover">
									<thead>
                                                                            <tr>
                                                                                <th>关系</th>
                                                                                <th>年龄</th>
                                                                                <th>身体状况</th>
                                                                                <th>是否有人照顾</th>
                                                                                <th>有无其他监护人照顾</th>
                                                                                <th>操作</th>
                                                                        </thead>
									<tbody>
                                                                            
									</tbody>
                                                                    </table>
                                                            </div>
							</div>
                                                    </div>
						</div>
                                            </div>
					</div>
                                    </div>
                                    <div class="panel-body-btn clearfix">
                                        <a href="javascript:;" class="record-body-save record-body-save1 fr" style="display:none;"></a>
                                        <a href="javascript:;" class="record-body-next record-body-next1 fr"></a>
                                        <a href="javascript:;" class="record-body-return record-body-btn1 fr"></a>
                                    </div>
				</div>
				<div class="panel-body panel-body-two none">
                                    <div class="panel-body-title"><div class="record-title-img"></div><a href="javascript:;" class="record-check-file">查看卷宗</a></div>
                                    <!-- 问题 -->
                                    <div class="panel-body-quesition">
                                        <!-- 1-单选框、2-多选框、3-矩阵、4-输入 -->
                                            <c:forEach items="${wqlVOList}" var="wqlVO" varStatus="st">
                                            <div class="quesition-one quesition-item">
                                                    <h6>${wqlVO.qgroupname}</h6>
                                                    <c:forEach items="${wqlVO.questionlist}" var="wxQuestion" varStatus="sts">
                                                        <input type="hidden" class="groupitem" name="grouplist" id="grouplist_${wqlVO.id}_${wxQuestion.wxQuestion.id }" value="${wqlVO.id}_${wxQuestion.wxQuestion.id}_0" />
                                                        <input type="hidden" class="scoreitem scorelist_${wqlVO.id}" name="scorelist" id="scorelist_${wqlVO.id}_${wxQuestion.wxQuestion.id }" value="${wqlVO.id}_${wxQuestion.wxQuestion.id}_0" />
							<p>
                                                            
                                                            <c:if test="${wxQuestion.answernum eq 1 }">
                                                                <label for="" data-qid="${wxQuestion.wxQuestion.id }" data-qgid="${wqlVO.id}" data-checkscore="${wxQuestion.wxAnswerList.get(0).score}" data-uncheckscore="0" data-cansid="${wxQuestion.wxAnswerList.get(0).id}" data-ucansid="0"><span>${wxQuestion.wxQuestion.qtitle}</span></label>
                                                            </c:if>
                                                           <c:if test="${wxQuestion.answernum eq 2 }">
                                                                <label for="" data-qid="${wxQuestion.wxQuestion.id }" data-qgid="${wqlVO.id}" data-checkscore="${wxQuestion.wxAnswerList.get(0).score}" data-uncheckscore="${wxQuestion.wxAnswerList.get(1).score}" data-cansid="${wxQuestion.wxAnswerList.get(0).id}" data-ucansid="${wxQuestion.wxAnswerList.get(1).id}"><span>${wxQuestion.wxQuestion.qtitle}</span></label>
                                                            </c:if>
							</p>
                                                    </c:forEach>
						</div>
                                      
					</c:forEach>
                                    </div>
                                    <div class="panel-body-btn clearfix">
					<a href="javascript:;" class="record-body-save record-body-save2 fr"></a> 
                                        <a href="javascript:;" class="record-body-next record-body-next2 fr"></a>
                                        <a href="javascript:;" class="record-body-return record-body-return2 fr"></a>
                                    </div>
				</div>
				<div class="panel-body panel-body-three none">
                                    <div class="panel-body-title">
                                        <div class="record-title-img"></div>
                                    </div>
                                    <div class="panel-body-scroe clearfix">
					<div id="scroeDiv" class="left fl">
                                            <input type="hidden" name="countScore" id="totalscore" value="" />
                                            <h5>总分值<b id="countScore" class="scroe-num">0</b>分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;综合全案材料建议<b id="scroeSuggest" class="scroe-suggest">不批准逮捕</b></h5>
                                            <table id="countScoreTable" class="scroe-table">
                                                <c:forEach items="${wqlVOList}" var="wqlVO" varStatus="st">
						<tr>
                                                    <td>${wqlVO.qgroupname}</td>
                                                    <td class="tdscore_${wqlVO.id}"><b>0</b>分</td>
						</tr>
                                                </c:forEach>
                                            </table>
					</div>
					<div class="right fl">
<!--                                            <a href="javascript:;" class="create-article"></a>
                                            <a href="javascript:;" class="create-table"></a>-->
                                            <a href="javascript:;" class="create-send"></a>
					</div>
                                    </div>
                                    <div class="panel-body-btn clearfix">
					<a href="javascript:;" class="record-body-save record-body-save3 fr" hassave="0"></a>
                                        <a href="javascript:;" class="record-body-next record-body-next3 fr" style="display:none;"></a>
                                        <a href="javascript:;" class="record-body-return record-body-return3 fr" style="display:none;"></a>
                                    </div>
				</div>
                            </form>
			</div>
                    </div>
		</div>
            </div>
	</div>
<div class="crime-msk none">
    <div class="crime-dialog">
	<div class="title">
            <div class="left fl"><span>查询已有嫌疑人</span></div>
            <div class="right fr"><a href="javascript:;" class="crime-msk-close"></a></div>
	</div>
        <div class="content">
            <form class="form-horizontal" action="${basePath }/wxUserlistAction_getjsonlist" id="searchlistform" method="post">
                <div class="form-group" style="margin-top:15px;">
                  <label for="truename" class="col-sm-2 control-label">姓名</label>
                  <div class="col-sm-3">
                      <input type="text" class="form-control" id="truename" name="truename" placeholder="按姓名查找">
                  </div>
                  <label for="idcardno" class="col-sm-2 control-label">证件号码</label>
                  <div class="col-sm-3">
                      <input type="text" class="form-control" id="idcardno" name="idcardno" placeholder="按证件号码查找">
                  </div>
                  <div class="col-sm-2"><button type="button" class="btn btn-default chaxunbtn" style="background-color: #446bcf;color:#ffffff;">查询</button></div>
                </div>
            </form>
                <div class="row" style="height: 300px;overflow: auto;">
                <table class="table table-condensed chaxuntable">
                    <thead>
                      <tr>
                        <th class="col-sm-1">#</th>
                        <th class="col-sm-2">姓名</th>
                        <th class="col-sm-1">性别</th>
                        <th class="col-sm-1">年龄</th>
                        <th class="col-sm-2">证件类型</th>
                        <th class="col-sm-2">证件号码</th>
                        <th class="col-sm-1">&nbsp;</th>
                      </tr>
                    </thead>
                    <tbody>
                      
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<!-- 浮层 -->
<div class="record-add-msk none">
            <a href="javascript:;" class="check-file-close"></a>
            <div class="check-file-dialog">
                <div class="swiper-container">
                    <ul class="swiper-wrapper">
                        <li class="check-file-item swiper-slide">
                            <img src="${basePath }/page/images/check-file-img1.png" alt="" />
                        </li>
                        <li class="check-file-item swiper-slide">
                            <img src="${basePath }/page/images/check-file-img1.png" alt="" />
                        </li>
                        <li class="check-file-item swiper-slide">
                            <img src="${basePath }/page/images/check-file-img1.png" alt="" />
                        </li>
                        <li class="check-file-item swiper-slide">
                            <img src="${basePath }/page/images/check-file-img1.png" alt="" />
                        </li>
                    </ul>
                    <!-- Add Pagination -->
                    <div class="swiper-pagination"></div>
                </div>
            </div>
            <div class="check-file-next-btn"></div>
            <div class="check-file-prev-btn"></div>
        </div>
    
<!-- 底部 -->
<jsp:include   page="common/bottom.jsp" flush="true"/>
<script type="text/javascript" src="${basePath }/page/js/distpicker.js"></script>
<script type="text/javascript" src="${basePath }/page/js/record.js"></script>
<script type="text/javascript">
    var fadminid=${wxAdmin.id };
	laydate.render({
		elem : '#test1'
	});
	//查看卷宗
	var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        paginationType: 'fraction',
        observer:true,
        observeParents:true
    });
    $('.check-file-next-btn').click(function() {
        swiper.slideNext();
    })
    $('.check-file-prev-btn').click(function() {
        swiper.slidePrev();
    })
    $(document).on('click', '.record-check-file', function() {
        $('.record-add-msk').fadeIn(400);
    })
    $(document).on('click', '.check-file-close', function() {
        $('.record-add-msk').fadeOut(400);
    })
	//查看卷宗结束
	//新增家庭成员
	var trAppend = '<tr><td><select name="familytypes[]"><c:forEach items="${familytypes }" var="familytype" varStatus="st"><c:if test="${st.index gt 0 }"><option value="${st.index }">${familytype}</option></c:if></c:forEach></select></td><td><input type="text" name="ages[]" value="45" /></td><td><select name="healthtypes[]"><option value="1">健康</option><option value="2">生病</option></select></td><td><select name="hasattends[]"><option value="1">是</option><option value="2">否</option></select><td><select name="hasotherattends[]"><option value="1">有</option><option value="2">无</optio<lect></td><td><a href="javascript:void(0)" id="record-delete"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span></a></td></tr>';
	$('.familyInfo-add-title .icon').click(function() {
		 $('.familyInfo-add-title tbody').append(trAppend);
	})
        function submitform(a){
            $.ajax({
                    type : "POST",
                    url : "${basePath}/wxUserdetailAction_add",
                    data : $('#addWxUserdetailForm').serialize(),
                    dataType: "json",
                    success : function(msg) {
                        if(a==0){
                            $(".record-body-save3").attr("userid",msg.data.userid);
                            $(".record-body-save3").attr("udetailid",msg.data.udetailid);
                            $(".record-body-save3").attr("eresultid",msg.data.eresultid);
                            $(".record-body-save3").attr("hassave","1");	
                        }else{
                            showDialogsuc('保存成功！！！');
                        }		
                    }
		});
        }
	/* 提交新增评估表单 */
	$('.record-body-save3').click(function() {
		if($(".record-body-save3").attr("hassave")=="1"){
                    showDialogsuc('保存成功！！！');
                }else{
                    setTimeout("showDialogsuc('保存成功！！！');",1000);
                }
	});

	/* 问题页面下一步，计算评估分数，并控制页面显隐 */
	$('.record-body-next2').click(function() {
		var totalscore=0;
                var iscore=0;
                var l=0;
                $(".panel-body-quesition label").each(function(i) {
                    if($(this).hasClass("checked")){
                        iscore=parseInt($(this).attr("data-checkscore"));
                        $("#grouplist_"+$(this).attr("data-qgid")+"_"+$(this).attr("data-qid")).val($(this).attr("data-qgid")+"_"+$(this).attr("data-qid")+"_"+$(this).attr("data-cansid"));
                        $("#scorelist_"+$(this).attr("data-qgid")+"_"+$(this).attr("data-qid")).val($(this).attr("data-qgid")+"_"+$(this).attr("data-qid")+"_"+iscore);
                    }else{
                        iscore=parseInt($(this).attr("data-uncheckscore"));
                        $("#grouplist_"+$(this).attr("data-qgid")+"_"+$(this).attr("data-qid")).val($(this).attr("data-qgid")+"_"+$(this).attr("data-qid")+"_"+$(this).attr("data-ucansid"));
                        $("#scorelist_"+$(this).attr("data-qgid")+"_"+$(this).attr("data-qid")).val($(this).attr("data-qgid")+"_"+$(this).attr("data-qid")+"_"+iscore);
                    }
                    $(".tdscore_"+$(this).attr("data-qgid")+" b").text(parseInt($(".tdscore_"+$(this).attr("data-qgid")+" b").text())+iscore);
                    totalscore=totalscore+iscore;
                    l++;
		});
                
                if(l==$(".panel-body-quesition label").length){
                    $("#countScore").text(totalscore);
                    $("#totalscore").val(totalscore);
                    if(totalscore<=-6){
                        //无羁押必要
                        $("#scroeSuggest").text("无羁押必要");
                    }else{
                        //有羁押必要
                        $("#scroeSuggest").text("有羁押必要");
                    }
//                    console.log(l+":"+$(".panel-body-quesition label").length);
                    $(".panel-body-two").hide();
                    $(".panel-body-three").show();
                    if($('.familyInfo-add-title tbody tr').length>0){
                        $("#hasfamilytypes").val("y");
                    }
                    submitform(0);
                }
                 
            });
	$('.quesition-item p label').click(function() {
		if($(this).hasClass("checked")){
                    $(this).removeClass("checked");
                }else{
                    $(this).addClass("checked");
                }
	})
        //发送审核信息
        $(".create-send").click(function(){
            if($(".record-body-save3").attr("hassave")=="1"){
                $.ajax({
                    type : "POST",
                    url : "${basePath}/wxChecklistAction_addchecklist",
                    data : {"fadminid":fadminid,"toadminid":1,"userid":$(".record-body-save3").attr("userid"),"udetailid":$(".record-body-save3").attr("udetailid"),"eresultid":$(".record-body-save3").attr("eresultid")},
                    dataType: "json",
                    success : function(msg) {
                        showDialogsuc('审核信息已发送成功！！！');	
                    }
		});
            }else{
                showDialog('请先保存数据！');
            }
        });
        $(".chaxun").click(function(){
            $(".crime-msk").fadeIn(400);
            getsearchuserlist();
        });
        $(".chaxunbtn").click(function(){
            getsearchuserlist();
        });
        var inputarr=["id","sex","truename","credtype","idcardno","nation","age","address","birthday","province","city","district"];
        $(document).on("click",".selanniu",function(){
            //执行代码
            if($(this).prop("checked")){
                 for(var i= 0;i<inputarr.length;i++){
                     $("#user_"+inputarr[i]).val($(this).attr("data-"+inputarr[i]));
                     if(inputarr[i]=="province"||inputarr[i]=="city"){
                         $("#user_"+inputarr[i]).trigger("change");
                     }
                 }
            } 
        })
        var chaxuntmp='<tr><th scope="row">@xuhao@</th><td>@truename@</td><td>@sexstr@</td><td>@age@</td><td>@credtypestr@</td><td>@idcardno@</td><td><input type="radio" class="selanniu" name="selanniu" data-id="@id@" data-sex="@sex@" data-truename="@truename@" data-credtype="@credtype@" data-idcardno="@idcardno@" data-nation="@nation@" data-age="@age@" data-province="@province@" data-city="@city@" data-district="@district@" data-address="@address@" data-birthday="@birthdayStr@" /></td></tr>';
        var tharr=["credtype","sex"];
        //searchlistform搜索用户
        function getsearchuserlist(){
            $.ajax({
                    type : "POST",
                    url : $('#searchlistform').attr("action"),
                    data : $('#searchlistform').serialize(),
                    dataType: "json",
                    success : function(data) {
                       if(data.success=="success"){
                           appenduserlist(data.data);
                       }
                    }
            });
        }
        function getshowvalue(key,value){
           return $("select[name='wxUserlist."+key+"'] option[value='"+value+"']").text();
        }
        function appenduserlist(data){
            $(".chaxuntable tbody").empty();
            var appendstr="";
            $.each(data,function(i,item){
                appendstr=chaxuntmp;
                appendstr=appendstr.replace("@xuhao@",i+1);
                for(var vk in item){ 
                    eval("var re = /@" + vk + "@/g;"); 
                    appendstr=appendstr.replace(re,item[vk]);
                    if($.inArray(vk,tharr)!=-1){
                        eval("var re2 = /@" + vk + "str@/g;");
                        var showstr=getshowvalue(vk,item[vk]);
                        appendstr=appendstr.replace(re2,showstr);
                    }
                }
                $(".chaxuntable tbody").append(appendstr);
            })
        }
        
        
</script>
